// miniprogram/pages/mall/home/index.js
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    noMore: false,
    keyWord:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.catalog) {
      this.catalog = options.catalog;
    }
    this.init();

    app.dataRequest("/rest/visitpage/visit.htm", {
      path: "my/home/index"
    }, this, "visitData");

  },
  init() {
    this.no = 1;
    var params = {};
    params.no = this.no;
    params.size = 10;
    params.auditState = "checked";
    if (this.catalog) {
      params.shopCatalog = this.catalog;
    }
    if(this.name){
      params.name = this.name;
    }
    app.dataRequest("/rest/shop/search.htm", params, this, "shops");
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.init();
    wx.stopPullDownRefresh();
  },
  onSearch() {
    this.name=this.data.keyWord;
    console.info(this.name);
    this.init();
  },
  onChange(e) {
    this.setData({
      keyWord: e.detail,
    });
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.info(this.totalPage);
    if (this.no < this.totalPage) {
      this.no = this.no + 1;
      this.setData({
        noMore: false
      });
      var params = {};
      params.no = this.no;
      params.size = 10;
      params.auditState = "checked";
      if (this.catalog) {
        params.shopCatalog = this.catalog;
      }
      if(this.name){
        params.name = this.name;
      }

      app.loadMore("/rest/shop/search.htm", params, this, "shops");

    } else {
      this.setData({
        noMore: true
      });
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})